pub use tabled::{Tabled, Table};

pub trait PrintTable{
    fn print_table(self);
}

impl<T> PrintTable for Vec<T>
where T: tabled::Tabled,
{
    fn print_table(self) {
        let table = Table::new(self).to_string();
        println!("{}",table);
    }
}

#[cfg(test)]
mod test{
    use crate::log_table::PrintTable;

    #[test]
    fn test_table(){
        use tabled::{Tabled};

        #[derive(Tabled)]
        struct Language {
            name: &'static str,
            designed_by: &'static str,
            invented_year: usize,
        }

        let languages = vec![
            Language{
                name: "C",
                designed_by: "Dennis Ritchie",
                invented_year: 1972
            },
            Language{
                name: "Go",
                designed_by: "Rob Pike",
                invented_year: 2009
            },
            Language{
                name: "Rust",
                designed_by: "Graydon Hoare",
                invented_year: 2010
            },
        ];

        languages.print_table();
    }
}